package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/product"
	product2 "git.900sui.cn/kc/rpcinterface/interface/product"
	"github.com/streadway/amqp"
	"log"
)

//支付成功, 修改销量和库存
func main() {
	rpcProduct := new(product.ShopProduct).Init()
	defer rpcProduct.Close()
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("products.log.addProduct"))
	log.Println(kcgin.AppConfig.String("products.queue.addProduct"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("products.queue.addProduct"), func(msg amqp.Delivery) {
		var args product2.ArgsAddProduct
		err := json.Unmarshal(msg.Body,&args)
		if err != nil {
			log.Fatalf("%v",err)
		}
		reply := false
		err = rpcProduct.MqAddProduct(context.Background(), &args, &reply)
		if err != nil {
			utils.Logerr.Printf("添加商品错误，args:%s, err:%s", args, err)
		}
	})

	if err != nil {
		utils.Logerr.Printf("添加商品错误任务错误, err: %s", err.Error())
	}
}